package com.example.springbootjson;

import com.alibaba.fastjson.JSON;
import com.example.springbootjson.vo.School;
import com.example.springbootjson.vo.UserVo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootJsonApplication {

    public static void main(String[] args) {
        UserVo userVo = new UserVo();
        userVo.setUserName("小明");
        userVo.setAge(18);
        userVo.setAddr("beijing");
        School school = new School();
        school.setName("beida");
        userVo.setSchool(school);
        userVo.setSchoolId("33");

        String s = JSON.toJSONString(school);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            String content = "{\n" +
                    "    \"addr\":\"shanghai\",\n" +
                    "    \"userName\":\"hhh\"\n" +
                    "}";
            UserVo userVo2 = objectMapper.readValue(content, UserVo.class);
            String s1 = objectMapper.writeValueAsString(userVo);
            System.out.println();
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        SpringApplication.run(SpringBootJsonApplication.class, args);
    }

}
